library(tidyverse)
library(ggmap)
library(maps)
library(mapdata)

#Insert your own google maps api key here to geocode
register_google(key = "AIzaSyBMd-611zpXp5YtT4fmMOIguvZt9F7_vmY")

to_geocode <- read_csv("/disk/bulkw/nencka/schooling_pandemic/2021_10_18_final/Temp/cleaned_city_covars.csv")


to_geocode <- as_data_frame(to_geocode) %>%
  mutate_geocode(address_to_code)

write_csv(to_geocode, "/disk/bulkw/nencka/schooling_pandemic/2021_10_18_final/Temp/cleaned_city_covarsgeocoded.csv")


#Create maps
ditch_the_axes <- theme(
  axis.text = element_blank(),
  axis.line = element_blank(),
  axis.ticks = element_blank(),
  panel.border = element_blank(),
  panel.grid = element_blank(),
  axis.title = element_blank(),
  panel.background = element_blank()
  )

  city_closures <- read_csv("/disk/bulkw/nencka/schooling_pandemic/2021_10_18_final/Temp/cleaned_city_covarsgeocoded.csv")
  
  city_closures  <-  city_closures %>%
    mutate(pop_1k = count/10000)
  
  usa <- map_data("usa") 
  states <- map_data("state")
  
  #Create base layer
  gg1 <- ggplot() + geom_polygon(data = states, aes(x=long, y = lat, group = group), fill = "white", color = "grey50") + 
    coord_fixed(1.3)
  

  #Create graph!
  gg2 <- gg1 + geom_point(data = city_closures, aes(x = lon, y = lat, alpha = days_closed, size = pop_1k), color = "blue") + 
    labs(alpha='Days closed', size = 'Population')  + scale_colour_continuous() +
    ditch_the_axes + guides(size=FALSE)

  print(gg2)
  ggsave("/disk/bulkw/nencka/schooling_pandemic/2021_10_18_final/Figures/maps_closures.png", gg2, dpi = 600)
  
  
  